home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Dev / ACE_Prgs.lha / speech / sprecog.lha / numrecog.b next >
Text File  |  1995-01-29  |  3KB  |  111 lines

  1. '...speech recognition with voice.library
  2.  
  3. LIBRARY exec
  4. LIBRARY dos
  5. LIBRARY voice
  6.  
  7. DECLARE FUNCTION AllocMem& LIBRARY exec
  8. DECLARE FUNCTION FreeMem LIBRARY exec
  9.  
  10. DECLARE FUNCTION xOpen& LIBRARY dos
  11. DECLARE FUNCTION xClose LIBRARY dos
  12. DECLARE FUNCTION xWrite LIBRARY dos
  13. DECLARE FUNCTION xRead& LIBRARY dos
  14.  
  15. DECLARE FUNCTION PickSampler LIBRARY voice
  16. DECLARE FUNCTION GainUp LIBRARY voice
  17. DECLARE FUNCTION GainDown LIBRARY voice
  18. DECLARE FUNCTION Learn LIBRARY voice
  19. DECLARE FUNCTION Recognize& LIBRARY voice
  20.  
  21. LONGINT max_num
  22.  
  23. '..words to recognise
  24. DIM word$(10)
  25. FOR i%=0 TO 8
  26.   READ word$(i%)
  27. NEXT
  28. DATA one,two,three,four,five,six,seven,eight,nine
  29.  
  30. '..Recognise() errors
  31. DIM rerror$(5)
  32. FOR i%=1 TO 4
  33.   READ rerror$(i%)
  34. NEXT
  35. DATA "No match.","Volume too high.","Volume too low.","Confused by noise."
  36.  
  37. '..Isaac's (my A500) speech characteristics
  38. DIM v%(9)
  39. FOR i%=0 TO 8
  40.   READ v%(i%)
  41. NEXT
  42. DATA 80,0,160,0,22900,64,10,0,0
  43.  
  44. PickSampler(0&)  '..Perfect SOUND Sampler
  45.  
  46. GainUp  '..volume up one notch
  47.  
  48. CLS
  49. PRINT
  50. PRINT "*** Speech Recognition of numbers 1 to";max_num;"***"
  51. PRINT
  52. INPUT "Read voice patterns from (F)ile or (R)e-learn? ",ans$
  53. IF UCASE$(ans$)="F" THEN
  54.   '..read stored patterns
  55.   INPUT "How many numbers in file: ",max_num
  56.   '..allocate memory for words and frequency-time maps
  57.   MapBuffer&=AllocMem(CLNG(304*max_num),2&)
  58.   INPUT "Enter name of file: ",f$
  59.   PRINT "Reading ";f$
  60.   fh&=xOpen&(SADD(f$),1005&)  '..OPEN FOR reading
  61.   xRead(fh&,MapBuffer&,CLNG(304*max_num))
  62.   xClose(fh&)
  63. ELSE
  64.   '..learn max_num words (numbers 1 to max_num)
  65.   INPUT "Specify how many numbers to learn: ",max_num
  66.   '..allocate memory for words and frequency-time maps
  67.   MapBuffer&=AllocMem(CLNG(304*max_num),2&)
  68.   FOR i&=0 TO max_num-1
  69.     Learn(MapBuffer&,SADD(word$(i&)),0&,i&,100&,75&)
  70.   NEXT
  71.   '..store words and maps in file
  72.   INPUT "Enter name of file: ",f$
  73.   fh&=xOpen&(SADD(f$),1006&)    '..OPEN FOR writing
  74.   xWrite(fh&,MapBuffer&,CLNG(304*max_num))
  75.   xClose(fh&)
  76. END IF
  77.  
  78. CLS
  79. PRINT
  80. PRINT "*** Speech Recognition of numbers 1 to";max_num;"***"
  81. PRINT
  82.  
  83. '..resolution?
  84. REPEAT
  85.   INPUT "Enter recognition resolution (hi = 0,lo = 1 or -1 to quit): ",res&
  86. UNTIL res&=-1 OR res&=0 OR res&=1
  87.  
  88. IF res& = -1 THEN cleanup
  89.  
  90. '..recognise words until left mouse button held down
  91. PRINT
  92. WHILE NOT MOUSE(0)
  93.   PRINT "speak number..."
  94.   wd%=Recognize(MapBuffer&,max_num,res&)
  95.   IF wd%>=0 THEN
  96.     PRINT word$(wd%)
  97.     SAY TRANSLATE$(word$(wd%)),v%
  98.   ELSE
  99.     PRINT rerror$(ABS(wd%))
  100.   END IF
  101. WEND
  102.  
  103. cleanup:
  104.   FreeMem(MapBuffer&,CLNG(304*max_num))
  105.  
  106.   GainDown  '..restore volume setting to that prior to running program
  107.  
  108.   LIBRARY CLOSE voice
  109.   LIBRARY CLOSE dos
  110.   LIBRARY CLOSE exec
  111.